home *** CD-ROM | disk | FTP | other *** search
/ Champak 132 (Alt) / Vol 132.iso / games / 3d_hyper / 3d_hyper.dcr / Scripts_9_Slider Behavior.ls < prev    next >
Encoding:
Text File  |  2011-06-09  |  2.4 KB  |  110 lines

  1. property pMaxPoint, pMinPoint, pWhichSlider, pDragging, pWidth
  2. global gCarAttributes, gRacers
  3.  
  4. on getPropertyDescriptionList me
  5.   list = [:]
  6.   addProp(list, #pWhichSlider, [#comment: "Which Slider?", #format: #symbol, #default: #acceleration, #range: [#brake, #acceleration, #turning]])
  7.   return list
  8. end
  9.  
  10. on beginSprite me
  11.   pBeginPoint = sprite(me.spriteNum).loc
  12.   pMaxPoint = sprite(me.spriteNum).loc + point(144, 0)
  13.   pMinPoint = pBeginPoint
  14.   pWidth = pMaxPoint.locH - pMinPoint.locH
  15.   me.loadStats()
  16. end
  17.  
  18. on exitFrame me
  19.   if pDragging then
  20.     theLocH = the mouseH
  21.     if theLocH < pMaxPoint.locH then
  22.       if theLocH > pMinPoint.locH then
  23.         me.setLoc(theLocH)
  24.       else
  25.         me.setLoc(pMinPoint.locH)
  26.       end if
  27.     else
  28.       me.setLoc(pMaxPoint.locH)
  29.     end if
  30.   end if
  31. end
  32.  
  33. on mouseEnter me
  34.   cursor(260)
  35. end
  36.  
  37. on mouseLeave me
  38.   if not pDragging then
  39.     cursor(-1)
  40.   end if
  41. end
  42.  
  43. on mouseDown me
  44.   me.grab()
  45. end
  46.  
  47. on mouseUp me
  48.   me.release()
  49. end
  50.  
  51. on mouseUpOutSide me
  52.   me.release()
  53. end
  54.  
  55. on grab me
  56.   cursor(290)
  57.   pDragging = 1
  58. end
  59.  
  60. on release me
  61.   pDragging = 0
  62.   cursor(-1)
  63. end
  64.  
  65. on setLoc me, theLocH
  66.   sprite(me.spriteNum).locH = theLocH
  67.   thePercent = (theLocH - pMinPoint.locH) / float(pWidth)
  68.   me.setStats(thePercent)
  69.   sendSprite(me.spriteNum - 1, #updateMask, thePercent)
  70. end
  71.  
  72. on loadStats me
  73.   theMin = gCarAttributes[pWhichSlider].min
  74.   theMax = gCarAttributes[pWhichSlider].max
  75.   theRange = theMax - theMin
  76.   if pWhichSlider = #brake then
  77.     theValue = gRacers[1].pBrakeGain
  78.   else
  79.     if pWhichSlider = #acceleration then
  80.       theValue = gRacers[1].pAccGain
  81.     else
  82.       if pWhichSlider = #turning then
  83.         theValue = gRacers[1].pTurnData.sensitivity
  84.       end if
  85.     end if
  86.   end if
  87.   thePercent = (theValue - theMin) / theRange
  88.   theLocH = (thePercent * pWidth) + pMinPoint.locH
  89.   me.setLoc(theLocH)
  90. end
  91.  
  92. on setStats me, thePercent
  93.   theMin = gCarAttributes[pWhichSlider].min
  94.   theMax = gCarAttributes[pWhichSlider].max
  95.   theRange = theMax - theMin
  96.   theVal = theMin + (theRange * thePercent)
  97.   if pWhichSlider = #brake then
  98.     gRacers[1].pBrakeGain = theVal
  99.   else
  100.     if pWhichSlider = #acceleration then
  101.       gRacers[1].pAccGain = theVal
  102.       gRacers[1].pMaxSpeed = ((gCarAttributes[#speed].max - gCarAttributes[#speed].min) * (1 - thePercent)) + gCarAttributes[#speed].min
  103.     else
  104.       if pWhichSlider = #turning then
  105.         gRacers[1].pTurnData.sensitivity = theVal
  106.       end if
  107.     end if
  108.   end if
  109. end
  110.